<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">
    <title></title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <script  src="js/jquery-1.8.0.js"></script>
    <link rel="stylesheet" type="text/css" href="css/maintable.css" ></link>
    <script>
        function  duo(th) {
            if(th.checked){
                $("input[class="+th.id+"]").attr("checked","checked");
            }else{
                $("input[class="+th.id+"]").removeAttr("checked");
            }

        }
    </script>
</head>
<body>
<h1>角色授权</h1>
<hr />
角色: ${roleInfo.roleName}
<form action="RoleServlet" method="post">
    <input type="hidden" name="flag"  value="updateRoleMenu">
    <input type="hidden" name="roleId" value="${roleInfo.id}"  >
    <table class="main_table">
        <tr>
            <th>一级权限</th><th>二级权限</th>
        </tr>
        <c:forEach var="m" items="${menuList }">
            <tr>
                <td><input name="id" type="checkbox" value="${m.id}" id="${m.id }" onclick="duo(this)"> ${m.menuName } </td>
                <td name="${m.id}">
                    <c:forEach var="m_sub" items="${m.subMenuList}">
                        <input type="checkbox" name="ids" value="${m_sub.id}" class="${m.id}" onclick="dan(this)"> ${m_sub.menuName} <br />
                    </c:forEach>
                </td>
            </tr>
        </c:forEach>

    </table>

    <input type="submit" value="提交" onclick="return confirm('确定提交吗')" >

</form>
${msg }
<script>
    var menuIdStr="${menuIdStr }";      //数据回显
    var menuIdArray=menuIdStr.split(",");
    Array.prototype.contains=function(e){
        for(var i=0;i<this.length;i++){
            if(this[i]==e){
                return true;
            }
        }
        return false;
    }
        $("input[name=ids]").each(function () {
            var menuId = this.value;
            if (menuIdArray.contains(menuId)) {
                this.checked = true;
            }

        });
        $("input[name=id]").each(function () {
            var menuId = this.value;
            if (menuIdArray.contains(menuId)) {
                this.checked = true;
            }
        });

</script>


</body>
</html>